package com.filesystem.file.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.filesystem.file.entity.User;
import com.filesystem.file.mapper.UserMapper;
import com.filesystem.file.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JayZhou
 * @since 2021-06-10
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    //注入Mapper ，注入时一定要看Mapper文件， 是否有@Mapper 注解

    @Autowired
    private  UserMapper userMapper;

    @Override
    public User selectByUserNamePassword(String username, String password) {
        //使用mybaits-plus 容器
        QueryWrapper queryWrapper = new QueryWrapper<>();
        //对比账号密码
        queryWrapper.eq("username",username);
        queryWrapper.eq("password",password);
        //返回查询结果
        return userMapper.selectOne(queryWrapper);
    }

    //@Override
    //public Map<String, Object> selectUser(int from, int size, Map<String, String> conditionMap) {
    //    Page<User>  page = new Page<User>(from,size);
    //    QueryWrapper queryWrapper = new QueryWrapper();
    //    queryWrapper.orderByDesc("id");
    //    for (String key :  conditionMap.keySet()){
    //        String valaue = conditionMap.get(key);
    //        if (valaue != null && valaue.length() !=0){
    //            queryWrapper.like(key,valaue);
    //        }
    //    }
    //    IPage<User> userIPage = userMapper.selectByPgEw(page,queryWrapper);
    //    Map<String, Object> map =  new HashMap<>();
    //    map.put("data",page.getRecords());
    //    map.put("count",(int)page.getTotal());
    //    return map;
    //}


}
